package com.common.hbase.domain;

import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;

public class ScanDomain {

    private String tableName;

    private Scan scan;

    public ScanDomain(String tableName) {

        this.tableName = tableName;

        scan = new Scan();

    }

    public String getTableName() {
        return tableName;
    }

    public Scan getScan() {
        return scan;
    }

    public void setScan(Scan scan) {
        this.scan = scan;
    }

    public ScanDomain addFamily(String columnFamily){
        scan.addFamily(Bytes.toBytes(columnFamily));
        return this;
    }

    public ScanDomain addColumn(String columnFamily, String... fields){
        if (fields==null||fields.length<=0){
            if (!columnFamily.isEmpty()){
                addFamily(columnFamily);
            }
        }else{
            if (!columnFamily.isEmpty()){
                for (String field : fields) {
                    scan.addColumn(Bytes.toBytes(columnFamily), Bytes.toBytes(field));
                }
            }else{
                System.out.println("Error : columnFamily NotNull");
            }
        }
        return this;
    }

    public ScanDomain setVersion(){
        scan.setMaxVersions();
        return this;
    }

    public ScanDomain setVersion(int version){
        scan.setMaxVersions(version);

        return this;
    }

}
